#include "GameScene.h"
#include "SimpleAudioEngine.h"

USING_NS_CC;

Scene* GameScene::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::create();
    
    // 'layer' is an autorelease object
    auto layer = GameScene::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool GameScene::init()
{

    if ( !Layer::init() )
    {
        return false;
    }
    
    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

	showStarMatrix();

	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = CC_CALLBACK_2(GameScene::onMyTouchBegan, this);
	getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);

	this->scheduleUpdate();
    
    return true;
}


void GameScene::showStarMatrix()
{
	matrix = StarMatrix::create();

	this->addChild(matrix);
}

bool GameScene::onMyTouchBegan(Touch* touch, Event* unused_event)
{
	Point point = touch->getLocation();
	if (matrix)
	{
		matrix->onTouch(point);
	}

	return true;
}

void GameScene::update(float delta) {
	if (matrix) {
		matrix->updateStar(delta);
	}
}